<?php

namespace Admin\Controller;
use Think\Controller;
use Think\Log;
use Org\Util\Page; 

class SponsorController extends BaseController {
	function _initialize() {
		parent::_initialize ();
	}

	public function index(){

        $this->display();
    }

//获取预售团购内容
    public function sponsorList()
    {
		$_listrows = I('request._listrows', '', 'trim');
        $keywords = I('request.keywords','','trim');
        if(!empty($keywords)){
            $_where['b.packagename|c.user_name']=array('like',"%{$keywords}%");
        }
       $type = I('request.blongtype',-1,'intval');
		if( $type != -1){
			if($type==1){
				$blongtype = 'presell';
			}else{
				$blongtype = 'group';
			}
			$_where['b.blongtype']=$blongtype;
		} 
        $start_time = I('request.start_time','','trim');
        $end_time = I('request.end_time','','trim');
        $str='';
        //如果两个为空，没有条件
        //否则 一个为空，一个有值，两个有值 
        if(!(empty($start_time) && empty($end_time))){ 
            $start_time = empty($start_time)?date("Y-m-d"):$start_time;
            $end_time = empty($end_time)?date("Y-m-d"):$end_time;
            if($start_time>$end_time){
                 $temp=$end_time;
                 $end_time=$start_time;
                 $start_time=$temp;
            }  
  
           $str =" and a.addtime between '".$start_time." 00:00:01' and '".$end_time." 23:59:59'"; 
        }  
        
        $str = ltrim(trim($str),'and');
        if(!empty($str)){
            $_where['_string']=$str;
        }
    $where_order['where'] = $_where;
        /*$where_order['order'] = ' last_transaction_time desc ';*/
        $where_order['listrows'] = $_listrows;
        $where_order["id"]="load_tb_div";
        $where_order["alias"]="a";
        $where_order["order"]="a.addtime desc";
        $where_order["field"]="a.*,b.packagename,b.blongtype,c.user_name";
        $where_order["join"]=array('inner join '.$this->dbprefix.'group_purchase_package b on a.packageid=b.packageid',' inner join '.$this->dbprefix.'users c on a.userid=c.user_id');   

        $_datalist = $this->_getListsFromModel('group_list', $where_order);
     /*print_r($_datalist);exit;*/
        $this->assign('_datalist', $_datalist);
        $this->display(); 
    
 

    }





}
?>
